<?php
class Questions{
	public $db;
	public function __construct()
	{
		$this->db = new Mysql();		
	}
	
	public function getAllType()
	{
		$sql = "SELECT * FROM q_type ";
		return $this->db->selectAllCache($sql);
	}
	public function getAllQuestions()
	{
		$sql = "SELECT a.*,b.name ,c.name as catename FROM q_lib a 
		LEFT JOIN q_type b ON a.`type` = b.id 
		LEFT JOIN q_cate c ON a.cate = c.id
		
		WHERE `status`=1 ";
		$page = new Page();	
		$page->eachNums=10;
		$list = $page->getPage($sql);
		$html = $page->htmlPage();
		return array('list'=>$list,'html'=>$html,'total'=>$page->allNums);
		
	}
	public function getCateByUserAndName($uid,$name){
		$sql = "SELECT * FROM q_cate WHERE uid = '$uid' AND name='$name' ";
		return $this->db->selectRow($sql);
		
	}
	public function getCateByUser($uid){
		$sql = "SELECT * FROM q_cate WHERE uid = '$uid' ORDER BY islast DESC,id DESC";
		return $this->db->selectAll($sql);		
	}
	public function getQuestionById($id){
		$sql = "SELECT a.*,b.name ,c.name as catename FROM q_lib a 
		LEFT JOIN q_type b ON a.`type` = b.id 
		LEFT JOIN q_cate c ON a.cate = c.id
		
		WHERE a.id = '$id' ";
		return $this->db->getRow($sql);
	}
	public function getQuesTitle($ids){
		$sql = "SELECT id ,question FROM q_lib WHERE id IN( $ids )";
		return $this->db->getAll($sql);
		
	}
}